﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace APP.HELPER.Utils.Security
{
    public class Decryptor
    {
        // Fields
        private EncryptionAlgorithm AlgoritmID;
        private byte[] IV;

        // Methods
        public Decryptor(EncryptionAlgorithm algID)
        {
            this.AlgoritmID = algID;
        }

        public Decryptor(EncryptionAlgorithm algID, byte[] iv)
        {
            this.AlgoritmID = algID;
            this.IV = iv;
        }

        public string Decrypt(string MainString, string key)
        {
            DecryptTransformer transformer = new DecryptTransformer(this.AlgoritmID, this.IV);
            transformer.SetSecurityKey(key);
            MemoryStream stream = new MemoryStream(Convert.FromBase64String(MainString.Trim()));
            CryptoStream stream2 = new CryptoStream(stream, transformer.GetCryptoTransform(), CryptoStreamMode.Read);
            StreamReader reader = new StreamReader(stream2);
            string str = reader.ReadLine();
            reader.Close();
            stream2.Close();
            stream.Close();
            return str;
        }

        // Properties
        public DecryptTransformer DecryptTransformer
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
            }
        }
    }

}
 

